package com.reworkssm.mybatisdemo.controller;


import com.reworkssm.mybatisdemo.domain.Login;
import com.reworkssm.mybatisdemo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AuthenticationController {

	@Autowired
	private AccountService accountService;

	@PostMapping(path = "/authorize")
	public ResponseEntity<String> authenticate(@RequestBody Login requestData) {
		String token = accountService.getLoginToken(requestData);
		if (token != null) {
			return ResponseEntity.ok().body(token);
		} else
			return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
	}

}

